import java.net.*; 
import java.io.*; 

public class Server_Main 
{ 
 protected Socket clientSocket;
 private ServerSocket serverSocket = null; 
 private int port=5000;
 public Server_Main(){
	 
 }
 public Server_Main(int port){
	this.port=port; 
 }
 public void strart() throws IOException{
	 System.out.println("inicio del socket");
	 this.serverSocket = new ServerSocket(port); 
	 LazadorClientesEnThread();
 }
 
 public int strart1() {
	 System.out.println("inicio del socket");
	 try{
		 this.serverSocket = new ServerSocket(port); 
		 LazadorClientesEnThread();
	 return 1;
	 }catch(SocketException e){return 0;} 
	 catch (IOException e) {
		 System.err.println("Could not listen on port:"+port); 
		    System.exit(1); 
	}
	return -1;
 }
 
 
 public void LazadorClientesEnThread()   { 
	 try { 
         while (true)
            {
             System.out.println ("llega una nueva conexion");
             Server_Thread temp = new Server_Thread (serverSocket.accept());
             temp.start();
           }
     } 
    catch (IOException e) 
        { 
         System.err.println("Accept failed."); 
         System.exit(1); 
        } 
   } 
 	

 
 public void STOP() throws IOException{
	 System.out.println("Fin del socket");
	 try {
         serverSocket.close(); 
        }
    catch (IOException e)
        { 
    	 System.err.println("Could not listen on port:"+port); 
         System.exit(1); 
        } 
   }
 }
 
